<?php

namespace Lib;

class Action {

	public function Load() {
		global $o;
		$sClass = $_GET ['a'] ? ucfirst ( $_GET ['a'] ) : 'Index';
		$sMethod = $_GET ['m'] ? $_GET ['m'] : 'index';
		$o->Action->$sClass->$sMethod ();
	}

	public function __get($sClassName) {
		global $o;
		$sClassName = ucfirst ( $sClassName );
		if (! defined ( 'ACTION' )) {
			$sActionPath = $o->Config->get ( 'action.path' );
			if (! $sActionPath) {
				$sActionPath = ROOT . '/action';
			} else {
				$sActionPath = ROOT . '/' . $sActionPath;
			}
			define ( 'ACTION', $sActionPath );
			define ( 'ACTION_AUTH', $o->Config->get ( 'action.auth' ) ? true : false );
		}
		$sFile = ACTION . '/' . $sClassName . '.class.php';
		try {
			if (is_file ( $sFile )) {
				require_once $sFile;
				$sClass = '\Action\\' . $sClassName;
				if (class_exists ( $sClass )) {
					$oObj = new $sClass ();
					$this->__set ( $sClassName, $oObj );
					return $oObj;
				} else {
					throw new ExceptionExt ( 'class no exist' );
				}
			} else {
				throw new ExceptionExt ( 'Action文件' . $sClassName . '不存在' );
			}
		} catch ( ExceptionExt $e ) {
			$e->showError ();
		}
	}

	public function __set($sName, $sValue) {
		$this->$sName = $sValue;
	}
}